package com.mentaleye.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.mentaleye.bean.PropertyBean;
import com.mentaleye.bean.StudentPropertyLoanRecordBean;
import com.mentaleye.biz.StudentPropertyLoanRecordBiz;
import com.mentaleye.biz.StudentsBiz;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;

@Controller
@RequestMapping("/studentPropertyLoanRecordController")
public class StudentPropertyLoanRecordController {

	@Autowired private StudentsBiz studentsBiz;
	
	@Autowired
	private StudentPropertyLoanRecordBiz recordBiz;

	@RequestMapping("/toPage")
	public String toPage() {
		return "lm/propertyLoanReturn/loanList";
	}
	
	@RequestMapping("/toInsertPage")
	public ModelAndView toInsertPage(@RequestBody PropertyBean propertyBean) {
		ModelAndView view=new ModelAndView("lm/propertyLoanReturn/loanAdd");
		view.addObject("property", propertyBean);
		view.addObject("studentList", this.studentsBiz.getBeanList());
		return view;
	}
	
	@RequestMapping("/toEditPage")
	public ModelAndView toEditPage(@RequestParam long id) {
		ModelAndView view = new ModelAndView("lm/propertyLoanReturn/loanEdit");
		view.addObject("record", this.recordBiz.getMapById(id));
		view.addObject("studentList", this.studentsBiz.getBeanList());
		return view;
	}

	@RequestMapping("/insertRecord")
	@ResponseBody
	public String insertProperty(StudentPropertyLoanRecordBean recordBean) {
		CommonResult result = this.recordBiz.insertBean(recordBean);
		return JSONObject.toJSONString(result);
	}

	@RequestMapping("/updateRecord")
	@ResponseBody
	public String updateProperty(StudentPropertyLoanRecordBean recordBean) {
		CommonResult result = this.recordBiz.updateBean(recordBean);
		return JSONObject.toJSONString(result);
	}

	@RequestMapping("/deleteRecord")
	@ResponseBody
	public String deleteProperty(@RequestBody List<Long> idList) {
		CommonResult result = this.recordBiz.deleteByList(idList);
		return JSONObject.toJSONString(result);
	}

	@RequestMapping("/getList")
	@ResponseBody
	public String getList(CommonPage page) {
		this.recordBiz.getListByPage(page);
		return page.toSHowPage();
	}
	
}
